package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.NursingTaskDoDto;
import com.zzyl.nursing.dto.NursingTaskDto;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.nursing.dto.NursingTaskCancelDto;
import com.zzyl.nursing.vo.NursingTaskListVo;
import com.zzyl.nursing.vo.NursingTaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理任务Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/nursing/nursingTask")
public class NursingTaskController extends BaseController {

    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 1.查询护理任务列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(NursingTaskDto dto) {
        startPage();
        List<NursingTaskListVo> list = nursingTaskService.selectNursingTaskList(dto);
        return getDataTable(list);
    }

    /**
     * 获取护理任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(nursingTaskService.selectTail(id));
    }

    /**
     * 3. 取消任务
     */
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody NursingTaskCancelDto dto) {
        nursingTaskService.cancel(dto);
        return success();
    }

    /**
     * 4. 任务执行
     */
    @PutMapping("do")
    public AjaxResult doIt(@RequestBody NursingTaskDoDto dto) {
        nursingTaskService.doIt(dto);
        return success();
    }

    /**
     * 任务改期
     */
    @PutMapping("/updateTime")
    public AjaxResult updateTime(@RequestBody NursingTaskDoDto dto) {
        nursingTaskService.updateTime(dto);
        return success();
    }

}
